<!-- 

-->
{literal}
<style type="text/css">

	#admin_vitrine .section
	{
		margin: 15px;
	}

	#admin_vitrine .active, #admin_vitrine .inactive,#admin_vitrine .account
	{
		display: inline-block;
		width: 30px;
		height: 15px;
		margin-left: 15px;
		margin-right: 15px;
	}

	#admin_vitrine .active	{	background: #0080C0;}
	#admin_vitrine .inactive{	background: #008000;}
	#admin_vitrine .account	{	background: #8080C0;}
	#admin_vitrine h3
	{
		font-size: 14px;
		margin: 15px;
		margin-top: 50px;
		padding: 5px;
		background-color: #333333;
		color: white;
	}
	#admin_vitrine h4
	{
		font-size: 10px;
		margin: 20px;
		margin-bottom: 5px;
		padding: 5px;
		color: #333333;
	}

	#admin_vitrine label
	{
		float: none;
	}

	#admin_vitrine table
	{
		border-collapse: collapse;
	}

		#admin_vitrine table tr
		{
			padding: 0;
		}
		
			#admin_vitrine table th
			{
				padding: 5px;
				background-color: #65CEED;
				color: white;
				border: 1px solid #65CEED;
			}
			
			#admin_vitrine table td
			{
				padding: 5px;
				border: 1px solid #f0f0f0;
			}
</style>
{/literal}
<script type="text/javascript">


	var fiches = {$statsFiches};
	var accounts = {$statsAccounts};
	var counter = 0;
	var list = new Array();
	
	function addToActionList(element, id_abo)
	{
		var actionListEl = document.getElementById('actionList');
		var index = list.indexOf(id_abo);
		
		if( element.checked )
		{
			if( index == -1 )
			{
				list.push(id_abo);
			}
		}
		else
		{
			if( index > -1 )
			{
				list.splice(index,1);
			}
		}
		
		actionListEl.value = list.join(',');
	}
	
	function getNumFichesBy(year,month,active)
	{
		var date = null;
		var results = 0;
		var i = fiches.length;
		while( --i > -1 )
		{
			date = fiches[i].date.split('-');
			date[0] = parseInt(date[0]);
			date[1] = parseInt(date[1]);
			if( date[0] == year && date[1] == month && fiches[i].active == active )
				results++;
		}
		
		return results;
	}	
	
	function getNumAccountsBy(year,month)
	{
		var date = null;
		var results = 0;
		var i = accounts.length;
		while( --i > -1 )
		{
			date = accounts[i].date_start.split('-');
			date[0] = parseInt(date[0]);
			date[1] = parseInt(date[1]);
			if( date[0] == year && date[1] == month )
				results++;
		}
		
		return results;
	}

	function drawChart(context,x,y,width,height,color, value)
	{
		context.save();
		context.fillStyle = color;
		context.fillRect(x,y,width,height);
		context.fill();
		context.fillStyle = "#333333";
		context.font = '10pt Arial';
		context.fillText(value+"", x + 5,y);
		context.restore();
	}
	
	function drawColumn(context,x, width, height, year,month)
	{
		var months = [	"-","Jan","Fev", "Mar", "Avr", "Mai",
						"Jui","Juil","Aou","Sep","Oct",
						"Nov","Dec"];
						
		var text = " "+months[month]+" "+year;
		
		context.save();
		context.beginPath();
		context.fillStyle = (counter % 2 == 0 ) ? "#DDDDDD" : "#FFFFFF";
		context.fillRect(x,0,width,height);
		context.fill();
		context.fillStyle = "#333333";
		context.font = '7pt Arial';
		context.fillText(text, x,15);
		context.restore();
		counter++;
	}
	
	window.onload = function()
	{
		var canvas = document.getElementById("stats");
		var context = canvas.getContext("2d");
		var date_start = '{$date_stats_start}';
		var date_end = '{$date_stats_end}';
		var tab1 = date_start.split('-');
		var tab2 = date_end.split('-');
		var startYear = parseInt(tab1[0]);
		var endYear = parseInt(tab2[0]);
		var startMonth = parseInt(tab1[1]);
		var endMonth = parseInt(tab2[1]);
		var i = 0;
		var max = 0;
		
		var value = 0 ;
		var topValue = Math.max(fiches.length, accounts.length);
		var totalMonth = ( ( endYear - startYear ) * 12 ) + endMonth - startMonth + 1;
		var stepY = canvas.height / topValue;
		
		var x = 0;
		var y = 0;
		var height = 0;
		var width = 30;
		canvas.width = totalMonth * width * 3;
		
		for( ; startYear <= endYear; startYear++ )
		{
			i = ( startYear == endYear ) ? 1 : startMonth;
			max = ( startYear == endYear ) ? endMonth : 12;
			for( ; i <= max; i++ )
			{
				drawColumn(context,x,width * 3, canvas.height, startYear,i);
				//actives
				value = getNumFichesBy(startYear, i, 1 );
				height = parseInt(value * stepY);
				height = ( height < 10 ) ? 10 : height;
				drawChart( context, x, canvas.height - height, width, height, "#0080C0", value );
				
				x+=width;
				
				//inactives
				value = getNumFichesBy(startYear, i, 0 );
				height = parseInt(value * stepY);
				height = ( height < 10 ) ? 10 : height;
				drawChart( context, x, canvas.height - height, width, height, "#008000", value );
				
				x+= width;
				
				//accounts
				value = getNumAccountsBy(startYear, i, 0 );
				height = parseInt(value * stepY);
				height = ( height < 10 ) ? 10 : height;
				drawChart( context, x, canvas.height - height, width, height, "#8080C0", value );
				
				x+= width;
				
			}
		}
	}

</script>
<div id="admin_vitrine">
	<div class="section">
		<h3>Générale </h3>
		<div>
			<form method="POST" action="{$ficheLink}">		
				<table>
					<tr>
						<td><label>{l s="Activer la sauvegarde automatique" mod='fichevitrine'}:</label></td>
						<td>
							<select name="autoSave">
								<option value="0" {if $autoSave == 0} selected="selected" {/if}>Non</option>
								<option value="1" {if $autoSave == 1} selected="selected" {/if}>Oui</option>
							</select>
						</td>
						<td><label>{l s="Timer de la sauvegarde automatique" mod='fichevitrine'}: </label></td>
						<td><input type="text" value="{$autoSaveTime}" name="autoSaveTime" /></td>
					</tr>
					<tr>
						<td><label>{l s="Taille (min) police" mod='fichevitrine'} : </label></td>
						<td><input type="text" value="{$startSize}" name="startSize" /></td>
						<td><label>{l s="Taille (max) police" mod='fichevitrine'}: </label></td>
						<td><input type="text" value="{$endSize}" name="endSize" /></td>
					</tr>
					<tr>
						<td><label>{l s="Liste de polices" mod='fichevitrine'} : </label></td>
						<td><textarea name="fontList">{$fontList}</textarea></td>
						<td></td>
						<td><input type="submit" name="saveConfig" value="Sauvegarder"/></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<div class="section">
		<h3>Clients</h3>
		
		<a href="{$customersLink}" title="Aller à la page Clients" target="_customers">Aller à la page Clients</a>
		
		<h4>Chercher un utilisateur par: </h4>
		<div style="margin: 15px">
			<form method="POST" action="{$ficheLink}">
				<table>
					<tr>
						<td><label>Nom:</label></td>
						<td><input type="text" name="lastname" value="" placeholder="Nom" /></td>
					
						<td><label>Prénom:</label></td>
						<td><input type="text" name="firstname" value="" placeholder="Prénom" /></td>
					
						<td><label>Société:</label></td>
						<td><input type="text" name="company" value="" placeholder="Société du client" /></td>
					
						<td><input type="submit" name="searchUser" value="Chercher" /></td>
					</tr>
				</table>
			</form>
		</div>
		
		<h4>{l s="Créer un compte pour l'utilisateur" mod='fichevitrine'}: </h4>
		<div>
			<form method="POST" action="{$ficheLink}">
				<input type="text" name="userEmail" placeholder="{l s="email de l'utilisateur" mod='fichevitrine'}" value=""/>
				<input type="submit" name="createUser" value="OK"/>
			</form>
		</div>
		
		<h4>Résultat:</h4>
		<div>		
			<table>
				<tr>
					<th>Id</th>
					<th>Nom</th>
					<th>Prénom</th>
					<th>Email</th>
					<th>Société</th>
				</tr>
				{foreach $result as $row }
				<tr>
					<td>{$row['id_customer']}</td>
					<td>{$row['lastname']}</td>
					<td>{$row['firstname']}</td>
					<td>{$row['email']}</td>
					<td>{$row['company']}</td>
				</tr>
				{/foreach}
			</table>
		</div>
	</div>
	<div class="section">
		<h3>Abonnements fiche vitrine</h3>
		
		
		<div>
			<form method="POST"  action="{$ficheLink}">
				<label>Filtrer les comptes fiche vitrine par:</label><br/>
				<input type="text" name="f_accountSurname" placeholder="Nom" value=""/>
				<input type="text" name="f_accountName" placeholder="Prénom" value=""/>
				<input type="text" name="f_accountMail" placeholder="E-mail" value=""/>
				<input type="submit" name="f_searchAccount" value="OK"/>
			</form>
		</div>
		<br/>
		
		<div>
			<form method="POST"  action="{$ficheLink}">
				<label>Définir l'espace de stockage pour les abonnements sélectionnés:</label>
				<input type="text" name="storeSizeAll" value="0" />
				<input type="submit" name="storeSizeAllSubmit" value="OK"/>
				<input type="hidden" name="actionList" id="actionList" value=""/>
			</form>
		</div>
		
		<table>
			<tr>
				<th></th>
				<th>{l s="Id" mod='fichevitrine'}</th>
				<th>{l s="Id client" mod='fichevitrine'}</th>
				<th>{l s="Nom" mod='fichevitrine'}</th>
				<th>{l s="Prénom" mod='fichevitrine'}</th>
				<th>{l s="Email" mod='fichevitrine'}</th>
				<th>{l s="Démarrage abonnement" mod='fichevitrine'}</th>
				<th>{l s="Fin abonnement" mod='fichevitrine'}</th>
				<th>{l s="Espace de stockage (Mo)" mod='fichevitrine'}</th>
				<th>{l s="2 en 1 (oui : 1 / non : 0)" mod='fichevitrine'}</th>
				<th>{l s="Actions" mod='fichevitrine'}</th>
			</tr>
			{foreach $aboList as $abo}
				<tr>
				<form method="POST"  action="{$ficheLink}">
					<td><input type="checkbox" name="aboCheckbox" onclick="addToActionList(this, {$abo->id_customer});" /> </td>
					<td><input type="hidden" 	name="id_abo" 		value="{$abo->id_abo}"   />{$abo->id_abo}</td>
					<td><input type="hidden" 	name="id_customer" 	value="{$abo->id_customer}" />{$abo->id_customer}</td>
					<td>{$abo->customer_lastname}</td>
					<td>{$abo->customer_firstname}</td>
					<td>{$abo->customer_email}</td>
					<td><input type="text" 		name="date_start" 	value="{$abo->date_start}" id="startDate"/></td>
					<td><input type="text" 		name="date_end" 	value="{$abo->date_end}" id="endDate"/></td>
					<td><input type="text" 		name="storeSize" 	value="{$abo->storeSize}"/></td>
					<td><input type="text" 		name="twoInOne" 	value="{$abo->twoInOne}"/></td>
					<td>
						<input type="submit" 	name="saveAbo" 		value="save"/>
						<a 	href="{$ficheLink}&id_customer={$abo->id_customer}&login=1}" 
							title="{l s='Se connecter en tant que' mod='fichevitrine'}"
							target="_connect">
							{l s='Se connecter' mod='fichevitrine'}
						</a>
					</td>
				</form>
				</tr>
			{/foreach}
		</table>
		
		<p style="text-align: center;">
            {if $numPagesAbo > 0 }
                {for $var=0 to $numPagesAbo }
                    {if $var == $currentPage}
                        <strong>
							
							<a href="{$ficheLink}&page={$var}" 
							title="page {$var}">{$var + 1}</a></strong>
                        {else}
                        <a href="{$ficheLink}&page={$var}" 
						title="page {$var}">{$var + 1}</a>
                    {/if}

                {/for}
            {/if}
        </p>
	</div>
	<div class="section">
		<h3>Thèmes</h3>
		<div style="height: 150px; overflow: scroll; width: 300px;">
			<table>
				<tr>
					<th>Id</th>
					<th>Nom</th>
					<th>Actions</th>
				</tr>
				{foreach $themes as $currentTheme}
				<tr>
					<form method="POST" action="{$ficheLink}&id_theme={$currentTheme->id}">
						<td>{$currentTheme->id}</td>
						<td>{$currentTheme->name}</td>
						<td><input type="submit" name="deleteTheme" value="Supprimer" /></td>
					</form>
				</tr>
				{/foreach}
			</table>
		</div>
		<form method="POST" action="{$ficheLink}">
			<label>Ajouter un thème</label>
			<input type="text" name="themeName" value=""/>
			<input type="submit" name="addTheme" value="OK"/>
		</form>
	</div>
	<div class="section">
		<h3>Types de biens</h3>
		<div style="height: 150px; overflow: scroll; width: 300px;">
			<table>
				<tr>
					<th>Id</th>
					<th>Nom</th>
					<th>Actions</th>
				</tr>
				{foreach $props as $currentProp}
				<form method="POST" action="{$ficheLink}&id_prop={$currentProp->id}">
				<tr>
					<td>{$currentProp->id}</td>
					<td>{$currentProp->name}</td>
					<td><input type="submit" name="deleteProp" value="Supprimer" /></td>
				</tr>
				</form>
				{/foreach}
			</table>
		</div>
		<form method="POST" action="{$ficheLink}">
			<label>Ajouter un type de bien</label>
			<input type="text" name="propName" value=""/>
			<input type="submit" name="addProp" value="OK"/>
		</form>
	</div>
	<div class="section">
		<h3>Statistiques</h3>
		<form method="POST" action="{$ficheLink}">
			<table>
				<tr>
					<td><label for="numCreated">Date (début):</label></td>
					<td><input type="text" name="date_stats_start" value="{$date_stats_start}"></td>
					<td><label for="numCreated">Date (fin):</label></td>
					<td><input type="text"  name="date_stats_end" value="{$date_stats_end}"></td>
					<td><input type="submit" value="Voir" name="show_stats"></td>
				</tr>
			</table>
		</form>
		<table>
			<tr>
				<td>fiches actives<span class="active"></span></td>
				<td>fiches inactives<span class="inactive"></span></td>
				<td>comptes crées<span class="account"></span></td>
			</tr>
		</table>
		<div style="width: 640px; height: 480; overflow: auto;">
			<canvas id="stats" width="640" height="480"></canvas>
		</div>
	</div>
</div>
